package com.chujian.framework.ws;


import com.chujian.framework.core.tsdata.TsData;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * 数据同步的消息定义
 */
@Getter
@Setter
@Accessors(chain = true)
@ToString
public class WsMsg extends TsData<Object> {

    public static final String MSG_TYPE_REQ = "req";
    public static final String MSG_TYPE_RESP = "resp";

    public static final Integer MSG_LEVEL_PRIORITY = 1; // 优先
    public static final Integer MSG_LEVEL_NORMAL = 3;   // 一般
    public static final Integer MSG_LEVEL_SLOW = 5;  // 推后，不重要

    public static final String MSG_TARGET_BROADCAST = "__PUSH_BROADCAST__";

    // 消息指令，用于消息逻辑处理
    private String msgCmd;  // 消息指令 sync
    private String msgType; // req 、resp

    private String target; // 接收目标
    private String source; // 发送者

    private Integer msgLevel; // 消息级别 1->5 紧急->一般
    private String reqId; // 请求ID，用于与响应进行对应

    private String busiType; // 业务类型
    private String busiId;   // 业务ID

    private boolean needRetry = true; // 是否需要重试，默认需要进行重试

    // ++++ 处理使用的变量
    // 失败次数
    private int errCnt;

    // 是否被消费
    private boolean isConsumed;

    private boolean isRetry = false;

    // ++++ 方法定义
    public void addErrCnt() {
        this.errCnt++;
    }

    /**
     * 是否是请求消息
     *
     * @return
     */
    public boolean isReq() {
        return MSG_TYPE_REQ.equals(this.msgType);
    }

    public String simpleToString() {
        return "WsMsg{" +
                "dataId=" + this.getDataId() + ", " +
                "dataMark=" + this.getDataMark() + ", " +
                "reqId=" + reqId +
                '}';
    }


}
